<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no"
          name="viewport">
    <title>评论管理-爱慈善</title>

    <link rel="stylesheet" href="background/modules/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="background/modules/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="background/modules/fontawesome/web-fonts-with-css/css/fontawesome-all.min.css">

    <link rel="stylesheet" href="background/modules/summernote/summernote-lite.css">
    <link rel="stylesheet" href="background/modules/flag-icon-css/css/flag-icon.min.css">
    <link rel="stylesheet" href="background/css/demo.css">
    <link rel="stylesheet" href="background/css/style.css">
    <link rel="stylesheet" href="background/css/common.css"/>
    <link rel="stylesheet" href="common/datatable/dataTables.bootstrap4.min.css"/>
    <link rel="stylesheet" href="background/css/xtiper.css"/>
    <script src="background/js/message.js"></script>
</head>

<body>
<div id="app">
    <div class="main-wrapper">
        <div class="navbar-bg"></div>

        <div th:replace="commons/admin-bar::navbar(currUri='comment')"></div>
        <div th:replace="commons/admin-bar::sidebar(currUri='comment')"></div>
        <div class="main-content">
            <section class="section">
                <h1 class="section-header">
                    <div><i class="icon ion ion ion-bookmark"></i> [[${name}]]</div>
                    <div class="float-right">
                        <select id="articleSelect" class="form-control" style="width:180px;height: 40px"
                                onchange="getComment()">
                            <option checked="checked">
                                请选择文章
                            </option>
                            <option th:each="article:${articles}" th:value="${article.title}">
                                <font size="2"> [[${article.title}]]</font>
                            </option>
                        </select>
                    </div>
                    <a href="" id="roaldData" style="display: none"></a>
                </h1>
                <div class="row">
                    <div class="col-xs-12 col-sm-12 col-md-12">
                        <div class="card mb-3">
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table id="example1" class="table table-bordered table-hover display"
                                           style="text-align: center">
                                        <thead>
                                        <tr>
                                            <th style="width: 10%">发布者</th>
<!--                                            <th style="width: 20%">评论类型</th>-->
                                            <th style="width: 30%">评论内容</th>
                                            <th style="width: 20%">发布时间</th>
                                            <th style="width: 20%">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody style="font-size: 13px">
                                        <tr th:each="comment:${comments}">
                                            <td th:text="${comment.userName}"></td>
<!--                                            <td th:text="${comment.type==1?'项目':'文章'}"></td>-->
                                            <td th:text="${comment.content}"></td>
                                            <td th:text="${#dates.format(comment.gmtCreate,'yyyy-MM-dd HH:mm:ss')}"></td>
                                            <td>
                                                <a th:href="@{/article(id=${comment.targetId})}" title="查看"
                                                   target="_blank" class="btn btn-sm btn-primary">
                                                    <i class="ion-eye ion"></i>
                                                </a>
                                                <button th:onclick="delComment([[${comment.id}]])" title="处理"
                                                        class="btn btn-sm btn-danger">
                                                    <i class="ion ion-trash-b"></i>
                                                </button>
                                                <button th:if="${comment.isFirst==0 && comment.replyId == null}"
                                                        th:onclick="commentUp([[${comment.id}]])"
                                                        title="置顶"
                                                        class="btn btn-sm btn-danger">
                                                    <i class="ion ion-arrow-up-c"></i>
                                                </button>
                                                <button th:if="${comment.isFirst==1 && comment.replyId == null}"
                                                        th:onclick="commentDown([[${comment.id}]])"
                                                        title="取消置顶"
                                                        class="btn btn-sm btn-danger">
                                                    <i class="ion ion-arrow-down-c"></i>
                                                </button>
                                            </td>
                                        </tr>
                                        </tbody>
                                        <thead>
                                        </thead>
                                    </table>
                                    <!--已通过-->
                                </div>

                            </div>
                        </div><!-- end card-->
                    </div>
                </div>
            </section>
        </div>
        <div th:replace="commons/admin-bar::footer"></div>
    </div>

</div>
<script src="background/modules/jquery.min.js"></script>
<script src="background/modules/popper.js"></script>
<script src="background/modules/tooltip.js"></script>
<script src="background/modules/bootstrap/js/bootstrap.min.js"></script>
<script src="background/modules/nicescroll/jquery.nicescroll.min.js"></script>
<script src="background/modules/scroll-up-bar/dist/scroll-up-bar.min.js"></script>
<script src="background/js/sa-functions.js"></script>

<script src="background/modules/chart.min.js"></script>
<script src="background/modules/summernote/summernote-lite.js"></script>

<script src="background/js/scripts.js"></script>
<script src="background/js/custom.js"></script>
<script src="background/js/demo.js"></script>
<script src="common/datatable/jquery.dataTables.min.js"></script>
<script src="common/datatable/dataTables.bootstrap4.min.js"></script>
<script src="common/js/board.js"></script>
<script src="background/js/xtiper.min.js"></script>

<script>
    // START CODE FOR BASIC DATA TABLE
    $(document).ready(function () {
        $('#example1').DataTable({
            language: {
                "sProcessing": "处理中...",
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "表中数据为空",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                },
                "oAria": {
                    "sSortAscending": ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            },
            "aoColumnDefs": [{"bSortable": false, "aTargets": [1]}],
            "order": [3, "desc"]
        });
    });
    // END CODE FOR BASIC DATA TABLE


    // START CODE FOR Child rows (show extra / detailed information) DATA TABLE

    /**
     * 审核文章
     * @param id
     */
    function delComment(id) {
        $.ajax({
            type: "POST",
            url: "delComment",
            data: {id: id},
            dataType: "json",
            success: function (data) {
                if (data['code'] == 200) {
                    alert("删除成功！");
                    window.location.reload();
                } else {
                    alert("服务器发生了一个错误");
                }
            }
        });
    }


    function getComment() {
        var title = $("#articleSelect").val();
        var herf = "my-comments?title=" + title
        $("#roaldData").attr("href", herf)
        $("#roaldData")[0].click();
    }
    function commentUp(id) {
        $.ajax({
            type: "POST",
            url: "commentIsFirst",
            data: {id: id,flag:0,type:2},
            dataType: "json",
            success: function (data) {
                if (data['code'] == 200) {
                    alert("置顶成功！");
                    window.location.reload();
                } else {
                    alert("该文章已存在置顶评论！");
                }
            }
        });
    }
    function commentDown(id) {
        $.ajax({
            type: "POST",
            url: "commentIsFirst",
            data: {id: id,flag:1,type:2},
            dataType: "json",
            success: function (data) {
                if (data['code'] == 200) {
                    alert("取消置顶成功！");
                    window.location.reload();
                } else {
                    alert("取消置顶失败！");
                }
            }
        });
    }

</script>
</body>
</html>
